package com.ruoyi.web.controller.offline;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.offline.domain.ItemGoodsprice;
import com.ruoyi.offline.service.IItemGoodspriceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品价格Controller
 * 
 * @author ruoyi
 * @date 2022-03-29
 */
@RestController
@RequestMapping("/offline/goodsprice")
public class ItemGoodspriceController extends BaseController
{
    @Autowired
    private IItemGoodspriceService itemGoodspriceService;

    /**
     * 查询商品价格列表
     */
    @PreAuthorize("@ss.hasPermi('offline:goodsprice:list')")
    @GetMapping("/list")
    public TableDataInfo list(ItemGoodsprice itemGoodsprice)
    {
        startPage();
        List<ItemGoodsprice> list = itemGoodspriceService.selectItemGoodspriceList(itemGoodsprice);
        return getDataTable(list);
    }

    /**
     * 导出商品价格列表
     */
    @PreAuthorize("@ss.hasPermi('offline:goodsprice:export')")
    @Log(title = "商品价格", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ItemGoodsprice itemGoodsprice)
    {
        List<ItemGoodsprice> list = itemGoodspriceService.selectItemGoodspriceList(itemGoodsprice);
        ExcelUtil<ItemGoodsprice> util = new ExcelUtil<ItemGoodsprice>(ItemGoodsprice.class);
        util.exportExcel(response, list, "商品价格数据");
    }

    /**
     * 获取商品价格详细信息
     */
    @PreAuthorize("@ss.hasPermi('offline:goodsprice:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(itemGoodspriceService.selectItemGoodspriceById(id));
    }

    /**
     * 新增商品价格
     */
    @PreAuthorize("@ss.hasPermi('offline:goodsprice:add')")
    @Log(title = "商品价格", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ItemGoodsprice itemGoodsprice)
    {
        return toAjax(itemGoodspriceService.insertItemGoodsprice(itemGoodsprice));
    }

    /**
     * 修改商品价格
     */
    @PreAuthorize("@ss.hasPermi('offline:goodsprice:edit')")
    @Log(title = "商品价格", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ItemGoodsprice itemGoodsprice)
    {
        return toAjax(itemGoodspriceService.updateItemGoodsprice(itemGoodsprice));
    }

    /**
     * 删除商品价格
     */
    @PreAuthorize("@ss.hasPermi('offline:goodsprice:remove')")
    @Log(title = "商品价格", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(itemGoodspriceService.deleteItemGoodspriceByIds(ids));
    }
}
